package com.dreamlin.basepro.base.view;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.dreamlin.basepro.common.DensityUtils;
import com.dreamlin.basepro.databinding.DialogLoadingBinding;

import java.util.Objects;

public class LoadingDialog extends Dialog {

    protected DialogLoadingBinding binding;

    public LoadingDialog(@NonNull Context context) {
        super(context);

        setCanceledOnTouchOutside(false);
        binding = DialogLoadingBinding.inflate(getLayoutInflater());
        Window window = getWindow();
        WindowManager.LayoutParams attributes;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
            attributes = Objects.requireNonNull(window).getAttributes();
        } else {
            attributes = window.getAttributes();
        }
        attributes.width = DensityUtils.dp2px(150f);
        attributes.height = DensityUtils.dp2px(110f);
        attributes.gravity = Gravity.CENTER;
        window.setAttributes(attributes);
    }

    public void setMsg(@Nullable String msg) {
        if (!TextUtils.isEmpty(msg))
            binding.tvMsg.setText(msg);
    }

}
